package assetservicelogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"
)

type ChartMultiSubjectAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewChartMultiSubjectAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChartMultiSubjectAddLogic {
	return &ChartMultiSubjectAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// ChartMultiSubjectAdd 创建多科目表项
func (l *ChartMultiSubjectAddLogic) ChartMultiSubjectAdd(in *property_service.ChartMultiSubject) (*property_service.Response, error) {
	// 获取多科目表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).ChartMultiSubject
	// 创建一个新的多科目表模型对象，不包含ID、TenantID、CreatedAt、UpdatedAt字段
	mod := &model.ChartMultiSubject{
		AccountsID:    in.AccountsID,    // 资产科目ID
		SubjectsID:    in.SubjectsID,    // 固定资产科目ID
		SubjectsName:  in.SubjectsName,  // 固定资产科目名称
		TenantID:      in.TenantID,      // 租户ID
		CreatedAtuser: in.CreatedAtuser, // 创建用户
		UpdatedAtuser: in.UpdatedAtuser, // 更新用户
	}
	// 使用上下文执行创建操作
	if err := m.WithContext(l.ctx).Create(mod); err != nil {
		// 如果创建失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 创建成功，返回成功响应
	return result.Suc().AddEd()
}
